#!/bin/bash                                                                                                

#SBATCH -c 8
#SBATCH -N 1
#SBATCH -t 6-23:59:00
#SBATCH -p huce_intel
#SBATCH --constraint=intel
#SBATCH --mem=2500
#SBATCH --mail-type=ALL
#SBATCH --no-requeue
#SBATCH --mail-user=kelvin_bates@g.harvard.edu
#SBATCH -o stdout.%j
#SBATCH -e stdout.%j

ctr=0
#sed -i "s/RTOL(i) = 1.0d-4/RTOL(i) = 1.0d-8/g" aromatics_kpp_Main.f90
#sed -i "s/ATOL(i) = 1.0d-3/ATOL(i) = 1.0d-8/g" aromatics_kpp_Main.f90

sed -i "s#(1.0001E-2)\*(..0E-.)#(1.0001E-2)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(1.0002E-2)\*(..0E-.)#(1.0002E-2)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
sed -i "s#(1.0003E-2)\*(..0E-.)#(1.0003E-2)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
for valHV in 1 5
do
    sed -i "s#SUN = ..0#SUN = $valHV.0#g" aromatics_kpp_Rates.f90
    for valH2O2 in 1 5
    do
        sed -i "s#(4.9999E-1)\*(..0#(4.9999E-1)\*($valH2O2.0#g" aromatics_kpp_Initialize.f90
        for valTEMP in 2 1 3 
        do
            sed -i "s#TEMP = 278 + .#TEMP = 278 + $valTEMP#g" aromatics_kpp_Initialize.f90
            for valAROMmag in 6 5 4 3
            do
                sed -i "s#(1.0001E-2)\*(..0E-.)#(1.0001E-2)\*(1.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
                for valNOmag in 9 8 7 6 5 4 3
                do
                    for valNO in 1 2 5
                    do
                        sed -i "s#(5.0004E-3)\*(..0E-.)#(5.0004E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                        rm *.exe *.o *.mod
                        make -f Makefile_aromatics_kpp
                        ./aromatics_kpp.exe
                        ctr=$[ctr+1]
                        mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_Porter_chamber_$ctr.dat
                    done
                done
            done
        done
    done
done
sed -i "s#(1.0001E-2)\*(..0E-.)#(1.0001E-2)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
for valHV in 1 5
do
    sed -i "s#SUN = ..0#SUN = $valHV.0#g" aromatics_kpp_Rates.f90
    for valH2O2 in 1 5
    do
        sed -i "s#(4.9999E-1)\*(..0#(4.9999E-1)\*($valH2O2.0#g" aromatics_kpp_Initialize.f90
        for valTEMP in 2 1 3
        do
            sed -i "s#TEMP = 278 + .#TEMP = 278 + $valTEMP#g" aromatics_kpp_Initialize.f90
            for valAROMmag in 6 5 4 3
            do
                sed -i "s#(1.0002E-2)\*(..0E-.)#(1.0002E-2)\*(1.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
                for valNOmag in 9 8 7 6 5 4 3
                do
                    for valNO in 1 2 5
                    do
                        sed -i "s#(5.0004E-3)\*(..0E-.)#(5.0004E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                        rm *.exe *.o *.mod
                        make -f Makefile_aromatics_kpp
                        ./aromatics_kpp.exe
                        ctr=$[ctr+1]
                        mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_Porter_chamber_$ctr.dat
                    done
                done
            done
        done
    done
done
sed -i "s#(1.0002E-2)\*(..0E-.)#(1.0002E-2)\*(0.0E-9)#g" aromatics_kpp_Initialize.f90
for valHV in 1 5
do
    sed -i "s#SUN = ..0#SUN = $valHV.0#g" aromatics_kpp_Rates.f90
    for valH2O2 in 1 5
    do
        sed -i "s#(4.9999E-1)\*(..0#(4.9999E-1)\*($valH2O2.0#g" aromatics_kpp_Initialize.f90
        for valTEMP in 2 1 3
        do
            sed -i "s#TEMP = 278 + .#TEMP = 278 + $valTEMP#g" aromatics_kpp_Initialize.f90
            for valAROMmag in 6 5 4 3
            do
                sed -i "s#(1.0003E-2)\*(..0E-.)#(1.0003E-2)\*(1.0E-$valAROMmag)#g" aromatics_kpp_Initialize.f90
                for valNOmag in 9 8 7 6 5 4 3
                do
                    for valNO in 1 2 5
                    do
                        sed -i "s#(5.0004E-3)\*(..0E-.)#(5.0004E-3)\*($valNO.0E-$valNOmag)#g" aromatics_kpp_Initialize.f90
                        rm *.exe *.o *.mod
                        make -f Makefile_aromatics_kpp
                        ./aromatics_kpp.exe
                        ctr=$[ctr+1]
                        mv aromatics_kpp.dat /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_Porter_chamber_$ctr.dat
                    done
                done
            done
        done
    done
done

sed -Ei "s#0-|1-|2-|3-|4-|5-|6-|7-|8-|9-#E-#g" /n/holyscratch01/jacob_lab/kbates/Aromatics/aromatics_kpp_GC_Porter_chamber_*.dat

# Exit normally
exit 0
#EOC
